package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.admin.ReportService;
import com.sky.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@Api("报表接口")
@RequestMapping("/admin/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 营业额统计
     */
    @GetMapping("/turnoverStatistics")
    @ApiOperation("统计营业额")
    public Result amountCollect(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end)
    {
        TurnoverReportVO turnoverReportVO = reportService.amountCollect(begin,end);
        return Result.success(turnoverReportVO);
    }

    /**
     * 订单统计
     */
    @GetMapping("/ordersStatistics")
    @ApiOperation("统计营业额")
    public Result orderCollect(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end)
    {
        OrderReportVO orderReportVO = reportService.orderCollect(begin,end);
        return Result.success(orderReportVO);
    }

    /**
     * 销量前10
     */
    @GetMapping("/top10")
    @ApiOperation("统计营业额")
    public Result top10(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                               @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end)
    {
        SalesTop10ReportVO reportVO = reportService.top10(begin,end);
        return Result.success(reportVO);
    }

    /**
     * 用户统计
     */
    @GetMapping("/userStatistics")
    public Result userStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,
                                 @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){
        UserReportVO userReportVO = reportService.userStatistics(begin, end);
        return Result.success(userReportVO);
    }
}
